package com.jellybean.augmentedreality;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;

import com.google.android.maps.MapView;

public class AugmentedReality extends MapView implements OnGestureListener {

	private GestureDetector gd;    
	private OnSingleTapListener singleTapListener;	

	public AugmentedReality(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		setupGestures();
	}

	public AugmentedReality(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		setupGestures();
	}

	public AugmentedReality(Context context, String apiKey) {
		super(context, apiKey);
		setupGestures();
	}

	private void setupGestures() {
		gd = new GestureDetector(this);  

		//set the on Double tap listener  
		gd.setOnDoubleTapListener(new OnDoubleTapListener() {

			public boolean onSingleTapConfirmed(MotionEvent e) {
				if (singleTapListener != null) {
					return singleTapListener.onSingleTap(e);
				} else {
					return false;
				}
			}

			public boolean onDoubleTap(MotionEvent e) {
				AugmentedReality.this.getController().zoomInFixing((int) e.getX(), (int) e.getY());
				return false;
			}

			public boolean onDoubleTapEvent(MotionEvent e) {
				return false;
			}

		});
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if (this.gd.onTouchEvent(ev)) {
			return true;
		} else {
			return super.onTouchEvent(ev);
		}
	}

	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		// TODO Auto-generated method stub
		return false;
	}

	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub

	}

	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		return false;
	}

	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub

	}

	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}
}
